package com.example.myapplication;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.example.myapplication.bean.Weapon;

public class DetailInfoActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail_info);
        TextView tvName= (TextView) findViewById(R.id.tv_detail_name);
        TextView tvPsw= (TextView) findViewById(R.id.tv_detail_password);
        String name="";
        String password="";
        //获取注册页面传递过来的用户名和密码
        Intent intent=getIntent();//获取注册页传递的intent
        name=intent.getStringExtra("username");
        password=intent.getStringExtra("userpsw");
        //展示到文本框
        tvName.setText("用户名："+name);
        tvPsw.setText("密码："+password);
        //点击按钮，需要回传数据的跳转
        Button btnShopping= (Button) findViewById(R.id.btn_detail_shopping);
        btnShopping.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //
                Intent intent1=new Intent(getApplicationContext(),ShopActivity.class);

                //需要回传数据
                startActivityForResult(intent1,1);

            }
        });
    }
    //
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //int weapon=data.getIntExtra("data",0);
        Weapon weapon= (Weapon) data.getSerializableExtra("data");//获取对象数据

        Toast.makeText(this,"回传过来的数据是："+weapon.getLife()+"--"+weapon.getSpeed()+"--"+weapon.getAttack(),Toast.LENGTH_LONG).show();

    }
}
